//
//  SearchResidencePermitViewModel.m
//  Jyxt
//
//  Created by 宫璞 on 2017/8/21.
//  Copyright © 2017年 DaLian Rental Housing Management. All rights reserved.
//

#import "SearchResidencePermitViewModel.h"
#import "NetTool.h"

@implementation SearchResidencePermitViewModel

+ (void)searchResidencePermitWhenSuccess:(BLOCK_SERVICE_REQUEST_SUCCESSNUMBER)success failed:(BLOCK_SERVICE_REQUEST_FAIL)failed{
    [NetTool postWithUrl:APIURL(API_SEARCHRESIDENCEPERMIT) data:@{} onSuccess:^(NSDictionary *response) {
        success(response);
    } onError:^(NSError *error) {
        failed(error);
    }];
}

+ (void)searchPoliceWithAreaId:(NSString *)areaId whenSuccess:(BLOCK_SERVICE_REQUEST_SUCCESSNUMBER)success fail:(BLOCK_SERVICE_REQUEST_FAIL)fail{
    [NetTool postWithUrl:APIURL(API_SEARCHRESIDENCEPOLICE) data:@{@"areaId":areaId} onSuccess:^(NSDictionary *response) {
        success(response);
    } onError:^(NSError *error) {
        fail(error);
    }];
}

+ (void)searchCommitWithData:(NSDictionary *)data whenSuccess:(BLOCK_SERVICE_REQUEST_SUCCESSNUMBER)success failed:(void (^)(NSString *reason))failed{
    [NetTool postWithUrl:APIURL(API_SEARCHCOMMIT) data:data onSuccess:^(NSDictionary *response) {
        if ([response[@"success"] boolValue]) {
            success(response);
        }
        else{
            failed(response[@"errmsg"]);
        }
    } onError:^(NSError *error) {
        failed(@"无法连接到服务器");
    }];
}

+ (NSString *)dictionaryToJson:(NSDictionary *)dic{
    
    NSString *tempStr = @"{";
    for (NSString *key in dic.allKeys) {
        tempStr = [NSString stringWithFormat:@"%@'%@':'%@',",tempStr,key,dic[key]];
    }
    tempStr = [tempStr stringByReplacingCharactersInRange:NSMakeRange(tempStr.length-1, 1) withString:@"}"];
    return tempStr;
}

+ (void)contractDetailWithUtoken:(NSString *)token id:(NSString *)ID whenSuccess:(BLOCK_SERVICE_REQUEST_SUCCESSNUMBER)success fail:(BLOCK_SERVICE_REQUEST_FAIL)fail{
    [NetTool postWithUrl:APIURL(API_CONTRACTDETAIL) data:@{@"utoken":token,@"id":ID} onSuccess:^(NSDictionary *response) {
        success(response);
    } onError:^(NSError *error) {
        fail(error);
    }];
}

@end
